package com.dongdong.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdong.mapper.TbGoodsDescMapper;
import com.dongdong.mapper.TbGoodsMapper;
import com.dongdong.mapper.TbItemMapper;
import com.dongdong.pojo.TbGoods;
import com.dongdong.pojo.TbGoodsDesc;
import com.dongdong.pojo.TbItem;
import com.dongdong.service.TbGoodsService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Service
@org.springframework.stereotype.Service
public class TbGoodsServiceImpl implements TbGoodsService {

    @Autowired
    private TbGoodsMapper tbGoodsMapper;

    @Autowired
    private TbGoodsDescMapper tbGoodsDescMapper;

    @Autowired
    private TbItemMapper tbItemMapper;

    @Override
    public boolean insert(TbGoods tbGoods, TbGoodsDesc tbGoodsDesc, TbItem tbItem) {

        try {
            tbGoods.setAuditStatus("0");
            tbGoodsMapper.insertSelective(tbGoods);
            tbGoodsDesc.setGoodsId(tbGoods.getId());
            tbGoodsDescMapper.insertSelective(tbGoodsDesc);
            tbItem.setGoodsId(tbGoods.getId());
            tbItem.setTitle(tbGoods.getGoodsName());
            tbItem.setCategoryid(1L);
            tbItem.setStatus("1");
//            创建时间
            tbItem.setCreateTime(new Date());
//            修改时间
            tbItem.setUpdateTime(new Date());
            tbItemMapper.insertSelective(tbItem);
            return true;
        }catch (Exception r){
            r.printStackTrace();
            return false;
        }
    }
}
